use color_eyre::eyre::eyre;
// use crate::error::Result;
use rodio::cpal::traits::HostTrait;
use rodio::DeviceTrait;
use color_eyre::Result; 

pub fn get_devices() -> Result<Vec<(String, rodio::Device)>> {
    Ok(rodio::cpal::default_host()
        .output_devices()?
        .map(|d| (d.name().unwrap_or("Unknown".to_string()), d))
        .collect())
}


use hound;

pub  fn check_wav_file(file_path: String ) -> Result<String> {
    let reader = hound::WavReader::open(file_path)
        .map_err(|e| format!("无法打开 WAV 文件: {}", e)); 
    
    if reader.is_err(){
        return Err(eyre!("WAV 文件格式错误:  ")); 
    }
    let reader = reader.unwrap(); 

    // 检查 WAV 文件的样本
    let spec = reader.spec();
    println!("音频文件信息: {:?}", spec);

    let samples: Vec<i16> = reader.into_samples::<i16>()
        .map(|s| s.unwrap())
        .collect();

    println!("样本数量: {}", samples.len());

    Ok("".into())
}
